<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
    <title>报表审核</title>
    <style>
    	.laydate-icon{
    		height:30px;
    		border-color:#B6B6B6
    	}
    	.north{
    		padding:8px 0px;
    		background:#f9f9f9;
    		overflow:hidden;
    	}
    	.tabs-wrap>.tabs>li>a{
			border-left:1px solid #438EB9!important;
			border-right:1px solid #438EB9!important;
			border-top:1px solid #438EB9!important;
		}
		.spanBtn{
			font-weight: bold;
			color: blue;
			cursor:pointer;
			margin:0 5px;
		}
    </style>
	  <script th:inline="javascript">
          /**读取request中的初始化数据*/
          var requestData = [[${requestData}]];
	  </script>
	<script>
		var bbshTabIndex = StoreCache.removeCache('bbshTabIndex');
		$(function(){
			initView();
		    $(this).registerManagerPage({callback:initData});
		})
		
		function initData(){
            initTableMethod.jcnbTb();
            $("body").css("visibility","visible");
		}
		
		function initView(){

            var readonly = !requestData["isManager"];
            $("#combogridYljgyb").combogrid({
                height: 30
                ,width: 250
                ,panelWidth: 500
                ,singleSelect: true
                ,pagination: true
                ,idField: 'YLJGDM'
                ,textField: 'YLJGMC'
                ,mode: "remote"
                ,readonly: readonly
                ,hasDownArrow: !readonly
                ,url: "/console/yljgxx/queryPageSummary.service"
                ,delay: 1000
                ,reversed: false
                ,columns:[[
                    {
                        field:'YLJGMC'
                        ,title:'机构名称'
                        ,width:240
                    }
                    ,{
                        field:'XZQHMC'
                        ,title:'行政区划'
                        ,width:80
                    }
                    ,{
                        field:'WSJGLBMC'
                        ,title:'机构类别'
                        ,width:80
                    }
                    ,{
                        field:'YYDJMC'
                        ,title:'机构等级'
                        ,width:80
                    }
                ]]
                ,onBeforeLoad: function(queryParams) {
                    var url = $(this).datagrid("options")["url"];
					/*URL不等空时再发送请求*/
                    if (!readonly) {
                        queryParams["pageSize"] = queryParams["rows"];
                        queryParams["pageNumber"] = queryParams["page"];
                        queryParams["YLJGMC"] = queryParams["q"];
                        return true;
                    }else{
                        return false;
                    }
                },
                onLoadSuccess : function(data){

                }
            });
            $("#combogridYljgnb").combogrid({
                height: 30
                ,width: 250
                ,panelWidth: 500
                ,singleSelect: true
                ,pagination: true
                ,idField: 'YLJGDM'
                ,textField: 'YLJGMC'
                ,mode: "remote"
                ,readonly: readonly
                ,hasDownArrow: !readonly
                ,url: "/console/yljgxx/queryPageSummary.service"
                ,delay: 1000
                ,reversed: false
                ,columns:[[
                    {
                        field:'YLJGMC'
                        ,title:'机构名称'
                        ,width:240
                    }
                    ,{
                        field:'XZQHMC'
                        ,title:'行政区划'
                        ,width:80
                    }
                    ,{
                        field:'WSJGLBMC'
                        ,title:'机构类别'
                        ,width:80
                    }
                    ,{
                        field:'YYDJMC'
                        ,title:'机构等级'
                        ,width:80
                    }
                ]]
                ,onBeforeLoad: function(queryParams) {
                    var url = $(this).datagrid("options")["url"];
					/*URL不等空时再发送请求*/
                    if (!readonly) {
                        queryParams["pageSize"] = queryParams["rows"];
                        queryParams["pageNumber"] = queryParams["page"];
                        queryParams["YLJGMC"] = queryParams["q"];
                        return true;
                    }else{
                        return false;
                    }
                },
                onLoadSuccess : function(data){

                }
            });

			$('#tabs').tabs({
				border: true,
			    fit: true,
			    tabWidth: "150",
				onSelect: function(title,index){
					var nowSelectTab = $(this).tabs('getTab',index); //获取到当前激活的tab
					var tableId = nowSelectTab.find("table").eq(1).attr("id");
					if(!StringUtils.isEmpty(tableId)){
						initTableMethod[tableId](); //初始化table
					}
				}
			})
			enterToQuery(queryTableData);
			
			if(!StringUtils.isEmpty(bbshTabIndex)){
				$('#tabs').tabs('select',parseInt(bbshTabIndex));
			}


		}
		
		/** 查询数据  */
		function queryTableData(){
            var tabIndex = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected')); //激活中的tab的下标
            var tbObj = ['jcnbTb','zhybTb'];
			$("#"+tbObj[tabIndex]).datagrid("load");
		}
		
		
		/** 审核报表  */
		function toCheckBb(row){
			StoreCache.setCache('bbshData', row);
			location.href = row.SHYM;
		}

        /** 撤回报表  */
        function recallBb(row){
            $.QuickAlert.alertConfirm({
                content : "确认将报表撤回？",
                callback : function() {
                    var index = parent.layer.prompt({
                        formType:2, //多行文本框
                        title : '撤回原因',
                        maxlength : 100,
                    },function(val, index2){
                        var params = {
                            ID: row.ID,
                            ZT: 4,
                            tableName: row.TB,
                            BZ: val
                        }
                        $.QuickRemote.AjaxJson(contextRoot + "wsj/checkBb", function(result){
                            if(result.state){
                                $.QuickAlert.alertNormal("撤回成功", {callback: function(){
                                    queryTableData(); //刷新
                                }});
                            }else{
                                var info = result["info"];
                                $.QuickAlert.alertFail({content: info["faultInfo"]});
                            }
						}, params);
                        parent.layer.close(index);
                    });
                }
            })
        }
		
		/** 初始化table的方法  */
		var initTableMethod = {
				//基础年报
				jcnbTb: function(){
					var query = $('#jcnbTb').data("query");
	    			if(!query){
	    				$('#jcnbTb').data("query",true);
	    			}else{
	    				return;
	    			}
	    			$('#jcnbTb').datagrid({
							idField : "QYXXID",
							striped : true,
							clickToSelect: true,
							fit:true,
							fitColumns: true,
							singleSelect: true,
							scrollbarSize:0,
							pagination : true,
							pageNumber : 1,
							pageSize : 10,
							pageList: [10, 25, 50, 100, 200],
							scrollBarSize:0,
							border: false,
							columns:[[
//										{field:'SHYM', title:'审核页面', width: 80, align: 'center'},
						   				{field:'NF', title:'年份', width: 80, align: 'center',formatter:function(value){
							    			value = value.split("/");
							    			var back = value[0];
							    			if(!StringUtils.isEmpty(value[1])){
                                                back += "年第" + value[1] + "季度";
											}
											return back;
										}}
										,{field:'JGMC', title:'机构名称', width: 120, align: 'center'}
										,{field:'JGLB', title:'机构类型', width: 80, align: 'center'}
										,{field:'XGSJ', title:'提交时间', width: 140, align: 'center'}
										,{field:'ZT', title:'状态', width: 80, align: 'center', formatter : function(value){
                                    		return formatBbzt(value);
										}}
										,{field:'cz', title:'操作', width: 80, align: 'center',formatter:function(value,row){
											var ZT = row.ZT;
											row = JSON.stringify(row).replace(/"/g, '&quot;');
											var btnXx = '<span class="spanBtn" onclick="toCheckBb(' + row + ')">详细</span>';
											if(ZT == 1){ //待审核的记录
                                                return '<span class="spanBtn" onclick="toCheckBb(' + row + ')">审核</span>';
											}else if(ZT == 3){//审核通过的记录
												var btnCh = '<span class="spanBtn" onclick="recallBb(' + row + ')">撤回</span>';
                                                return btnCh + btnXx;
                                            }else{
                                                return btnXx;
											}
										}}
							]],
							onBeforeLoad: function(params){
                                var yljgxx = getQueryFormValue("#combogridYljgnb");
                                params = $.extend(params,yljgxx);
								getContainerDataByClassName('nbCondition','condition',params);//查询条件
							},
							onLoadSuccess: function(data){
// 								alert(JSON.stringify(data))
							},
							url: contextRoot+"wsj/queryNbByPage.service"
					})
				},
				//综合月报
				zhybTb: function(){
					var query = $('#zhybTb').data("query");
	    			if(!query){
	    				$('#zhybTb').data("query",true);
	    			}else{
	    				return;
	    			}
	    			$('#zhybTb').datagrid({
							idField : "QYXXID",
							striped : true,
							clickToSelect: true,
							fit:true,
							fitColumns: true,
							singleSelect: true,
							scrollbarSize:0,
							pagination : true,
							pageNumber : 1,
							pageSize : 10,
							pageList: [10, 25, 50, 100, 200],
							scrollBarSize:0,
							border: false,
							columns:[[
//								{field:'SHYM', title:'审核页面', width: 80, align: 'center'},
								{field:'YF', title:'月份', width: 80, align: 'center'}
								,{field:'JGMC', title:'机构名称', width: 120, align: 'center'}
								,{field:'JGLB', title:'机构类型', width: 80, align: 'center'}
								,{field:'XGSJ', title:'提交时间', width: 140, align: 'center'}
								,{field:'ZT', title:'状态', width: 80, align: 'center',formatter : function(value){
                            		return formatBbzt(value);
								}}
								,{field:'cz', title:'操作', width: 80, align: 'center',formatter:function(value,row){
									var ZT = row.ZT;
									row = JSON.stringify(row).replace(/"/g, '&quot;');
                                    var btnXx = '<span class="spanBtn" onclick="toCheckBb(' + row + ')">详细</span>';
                                    if(ZT == 1){ //待审核的记录
                                        return '<span class="spanBtn" onclick="toCheckBb(' + row + ')">审核</span>';
                                    }else if(ZT == 3){//审核通过的记录
                                        var btnCh = '<span class="spanBtn" onclick="recallBb(' + row + ')">撤回</span>';
                                        return btnCh + btnXx;
                                    }else{
                                        return btnXx;
                                    }
								}}
							]],
							onBeforeLoad: function(params){
                                var yljgxx = getQueryFormValue("#combogridYljgyb");
                                params = $.extend(params,yljgxx);
								getContainerDataByClassName('ydqCondition','condition',params);//查询条件
							},
							url: contextRoot+"wsj/queryYbByPage.service"
					})
				}
		}

        /**获取查询表单的值*/
        function getQueryFormValue(id) {
            var params = {};
            var item = $(id).combogrid("grid").datagrid("getSelected");
            if(item){
                params["YLJGID"] = item["PTJGID"];
            }else{
                params["YLJGMC"] = $(id).combogrid("getText");
            }
            return params;
        }
		
		//报表状态--格式化
		function formatBbzt(bbdm){
            var bbztArr = StoreCache.getCache("TB_ZY_BBZT");
            if(!$.isEmptyObject(bbztArr) && !$.isEmptyObject(bbztArr = bbztArr.data)){
                $.each(bbztArr, function(){
                    if(this.XMDM==bbdm){
                        bbdm = this.XMMC;
                    }
                })
			}
			return bbdm;
		}

	</script>
  </head>
  
  <body style="visibility:hidden">
		<div id="tabs" class="easyui-tabs" fit="true" border="false">
			<div title="基础报表">
				<div class="easyui-layout" border="false" fit="true">
					<div region="north" class="north" border="false">
						<form action="downloadQycx.service" method="post" enctype="multipart/form-data" id="downloadAllForm">
							<table class="form-table" id="nbCondition">
								<tr>
									<td class="td-text">年份：</td>
									<td class="td-content">
										<input class="form-control laydate-icon condition" id="NF" name="NF"  
										onclick="WdatePicker({dateFmt:'yyyy'})" />
									</td>
									<td class="td-text">机构名称：</td>
									<td class="td-content">
										<input id="combogridYljgnb" />
									</td>
									<td class="td-text">状态：</td>
									<td class="td-content">
										<select name="ZT" class="form-control condition" style="width: 100%;" cacheTable="TB_ZY_BBZT">
										</select>
									</td>
									<td class="td-text" style="text-align:center;">
										<button class="btn btn-info" type="button" onclick="queryTableData()">查询</button>
									</td>
								</tr>
							</table>
						</form>
					</div>
					<div region="center" border="false">
						<table id="jcnbTb"></table>
					</div>
				</div>
			</div>
			
			
			
			
			
			<div title="综合报表">
				<div class="easyui-layout" border="false" fit="true">
					<div region="north" class="north" border="false">
						<form action="downloadQycx.service" method="post" enctype="multipart/form-data" id="downloadYdqForm">
							<table class="form-table" id="ydqCondition">
								<tr>
									<td class="td-text">月份：</td>
									<td class="td-content">
										<input class="form-control laydate-icon condition" id="YF" name="YF" 
										onclick="WdatePicker({dateFmt:'yyyyMM'})" />
									</td>
									<td class="td-text">机构名称：</td>
									<td class="td-content">
										<input id="combogridYljgyb" />
									</td>
									<td class="td-text">状态：</td>
									<td class="td-content">
										<select  name="ZT" class="form-control condition" style="width: 100%;" cacheTable="TB_ZY_BBZT">
										</select>
									</td>
									<td class="td-text" style="text-align:center;">
										<button class="btn btn-info" type="button" onclick="queryTableData()">查询</button>
									</td>
								</tr>
							</table>
						</form>
					</div>
					<div region="center" border="false">
						<table id="zhybTb"></table>
					</div>
				</div>
			</div>
		</div>
  </body>
</html>
